home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- import wx
- import wx.html as wx
- from datetime import datetime, date, timedelta
- import time
- from gui import skin
- from gui.imwin.styles.stripformatting import strip
- from gui.browser.webkit import WebKitWindow
- from common import pref, profile, prefprop
- from util import Storage as S, import_function, takemany, toutc, fromutc
- from logging import getLogger
- log = getLogger('msgarea')
- AUTORESP = _('[Auto-Response] ')
-
- def history_enabled():
- if pref('conversation_window.show_history', True):
- pass
- return pref('log.ims', True)
-
-
- def should_show_time(tstamp1, tstamp2):
- return fromutc(tstamp1).date() != fromutc(tstamp2).date()
-
-
- class MessageArea(WebKitWindow):
-
- def __init__(self, parent, header_enabled = True):
- WebKitWindow.__init__(self, parent)
- self.inited = False
- self.header_enabled = True
-
- date_context_format = '%A, %B %d, %Y'
- show_fonts = prefprop('appearance.conversations.show_message_fonts', True)
- show_colors = prefprop('appearance.conversations.show_message_colors', True)
- show_emoticons = prefprop('appearance.conversations.emoticons.enabled', True)
- htmlize_links = prefprop('appearance.conversations.htmlize_links', True)
-
- def init_content(self, theme, chatName = None, buddy = None, show_history = True):
- self.theme = theme
- now = datetime.now()
- self.tstamp = toutc(datetime(now.year, now.month, now.day))
- if self.header_enabled:
- pass
- show_header = pref('appearance.conversations.show_header', False)
- initialContents = theme.initialContents(chatName, buddy, show_header)
- self.SetPageSource(initialContents, theme.baseUrl)
- if show_history and history_enabled() and buddy is not None:
- self.show_history(buddy)
-
- self.inited = True
-
-
- def show_history(self, buddy):
- num_lines = max(0, pref('conversation_window.num_lines', 5, int))
- if num_lines > 0:
- msgobjs = reversed(list(takemany(num_lines, buddy.history)))
- self.replay_messages(msgobjs, buddy)
-
-
-
- def replay_messages(self, msgobjs, buddy, context = True):
- next = False
- oldname = None
- olddirection = None
- for msg in msgobjs:
- name = msg.buddy.name
- direction = msg.type
- if oldname == name:
- pass
- next = direction == olddirection
- msg.buddy = buddy.protocol.get_buddy(name)
- self.format_message(direction, msg, next, context = context)
- oldname = name
- olddirection = direction
-
-
-
- def show_header(self, show):
- return self.RunScript(self.theme.show_header_script(show))
-
-
- def date_status(self, dt):
- format_dt = fromutc(dt)
- return S(message = format_dt.strftime(self.date_context_format), timestamp = dt, buddy = None, type = None)
-
-
- def format_message(self, messagetype, messageobj, next = False, context = False):
- if messagetype != 'status':
- msgtime = messageobj.timestamp
- if msgtime is None:
- msgtime = datetime.utcnow()
-
- if should_show_time(self.tstamp, msgtime):
- self.format_message('status', self.date_status(msgtime), next = False, context = context)
- next = False
-
- self.tstamp = msgtime
-
- content_type = getattr(messageobj, 'content_type', None)
- if content_type is not None:
- if content_type == 'text/plain':
- preserve_whitespace = preserve_whitespace
- import util
- messageobj.message = messageobj.message.encode('xml')
- messageobj.message = preserve_whitespace(messageobj.message)
-
-
- if self.theme.allow_text_colors:
- pass
- show_colors = self.show_colors
- show_emoticons = None if self.show_emoticons else None
- transforms = dict(emoticons = show_emoticons, links = self.htmlize_links, spaces = True)
- (stripped, strip_values) = strip(messageobj.message, formatting = not (self.show_fonts), colors = not show_colors, plaintext_transforms = transforms)
- messageobj = messageobj.copy()
- messageobj.message = stripped
- if getattr(messageobj, 'has_autotext', False):
- extra = { }
- else:
- extra = dict(has_autotext = True, autotext = AUTORESP)
- if self.show_colors:
- extra.update(handle_colors(strip_values))
-
- (func, msg) = self.theme.format_message(messagetype, messageobj, next, context, **extra)
- if func:
- script = "%s('%s');" % (func, js_escape(msg))
- self.RunScript(script)
-
-
-
-
- def handle_colors(vals):
- bodycolor = None
- if 'bgcolor' in vals:
- bodycolor = vals['bgcolor'][0]
- elif 'back' in vals:
- bodycolor = vals['back'][0]
-
- if bodycolor:
- return {
- 'textbackgroundcolor': bodycolor }
-
- return { }
-
-
- def js_escape(msg):
- return msg.replace('\\', '\\\\').replace('\n', '\\\n').replace('\r', '\\\r').replace("'", ''')
-
-